﻿package mortal.game.view.pack.other
{
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.interfaces.*;

    public class MoneyCardPackageWin extends BaseWindow
    {
        private var _bg:GImageBitmap;
        private var _imgTip1:GImageBitmap;
        private var _imgTip2:GImageBitmap;
        private var _rechargeBtn:GLoadingButton;
        private var _getGiftBtn:GLoadingButton;
        private var _dayTxt:GTextFiled;
        private var _rechargeNumTxt:GTextFiled;
        private var _diamondBmp:GBitmap;
        private var _diamondTxt:GTextFiled;
        private var _itemNumTxt:GTextFiled;
        private var _itemData:ItemData;
        private var _item:BaseItem;
        private var _rewardNumBmpTxt:BitmapNumberText;
        private var _canTake:Boolean = false;
        private static var _instance:MoneyCardPackageWin;

        public function MoneyCardPackageWin(param1:ILayer = null)
        {
            if (_instance != null)
            {
                throw new Error(" MoneyCardPackageWin 单例");
            }
            this.title = Language.getString(35461);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            setSize(342, 412);
            this._bg = UIFactory.gImageBitmap(ImagesConst.moneyCardWinBg, 5, 36, this);
            this._imgTip1 = UIFactory.gImageBitmap(ImagesConst.moneyCardWinTxt1, 50, 158, this);
            this._imgTip2 = UIFactory.gImageBitmap(ImagesConst.moneyCardWinTxt2, 10, 160, this);
            this.pushUIToDisposeVec(UIFactory.label(Language.getString(35462), 20, 310, 500, 25, TextFormatAlign.LEFT, this, false, 65280));
            this._dayTxt = UIFactory.gTextField(Language.getString(35463), 102, 156, 100, 25, this, GlobalStyle.textFormatHuang2.setSize(16).setBold(true));
            var _loc_1:* = GlobalStyle.textFormatHuang2.setSize(16).setBold(true);
            _loc_1.align = TextFormatAlign.CENTER;
            this._rechargeNumTxt = UIFactory.gTextField("0", 112, 156, 100, 25, this, _loc_1);
            this._rewardNumBmpTxt = UIFactory.bitmapNumberText(262, 156, "GuildNewBuildingNum2.png", 21, 24, -10, this, 13, 1);
            this._item = UICompomentPool.getUICompoment(BaseItem);
            this.addChild(this._item);
            this._item.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this._item.x = 140;
            this._item.y = 220;
            this._diamondBmp = UIFactory.gBitmap(ImagesConst.zuanshi, 146, 226, this);
            this._itemNumTxt = UIFactory.gTextField("200", 180, 266, 100, 25, this, GlobalStyle.textFormatBai);
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.LockIcon, 145, 225, this));
            this._diamondTxt = UIFactory.gTextField("", 100, 380, 220, 50, this, GlobalStyle.textFormatHuang.setSize(16).setBold(true));
            this._rechargeBtn = UIFactory.gLoadingButton(ResFileConst.RechargeBtn, 48, 340, 114, 33, this);
            this._rechargeBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._rechargeBtn.drawNow();
            this._getGiftBtn = UIFactory.gLoadingButton(ResFileConst.GetGiftBtn, 170, 340, 114, 33, this);
            this._getGiftBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._getGiftBtn.drawNow();
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            if (event.target == this._rechargeBtn)
            {
                GameUtil.gotoRecharge(ModuleTypeConst.MoneyCardPackage);
            }
            else if (event.target == this._getGiftBtn)
            {
                if (this._canTake)
                {
                    GameController.pack.useMoneyCard(this._itemData.serverData.uid, this._itemData.itemCode, 1);
                    MoneyCardPackageWin.instance.hide();
                }
                else
                {
                    MsgManager.showRollTipsMsg(Language.getString(35464));
                }
            }
            return;
        }// end function

        public function set itemData(param1:ItemData) : void
        {
            this._itemData = param1;
            var _loc_2:* = param1.itemInfo.effect;
            this._itemNumTxt.text = String(_loc_2);
            this._item.toolTipData = Language.getString(35465) + String(_loc_2);
            var _loc_3:* = Cache.instance.rebate.rechargeSum;
            this._diamondTxt.htmlText = Language.getString(35466) + String(_loc_3);
            this._dayTxt.text = Language.getStringByParam(35467, String(this._itemData.itemInfo.feedMount));
            var _loc_4:* = this._itemData.itemInfo.effectEx;
            this._rechargeNumTxt.text = String(_loc_4);
            this._rewardNumBmpTxt.text = String(_loc_2);
            if (this._itemData.itemInfo.effectEx > 0)
            {
                this.setDayType2();
            }
            else
            {
                this.setDayType1();
            }
            if (_loc_3 >= _loc_4)
            {
                this.setStyle2();
                this._canTake = true;
            }
            else
            {
                this.setStyle1();
                this._canTake = false;
            }
            return;
        }// end function

        private function setDayType1() : void
        {
            this._imgTip1.visible = true;
            this._imgTip2.visible = false;
            this._dayTxt.x = 102;
            this._rechargeNumTxt.visible = false;
            this._rechargeBtn.visible = false;
            this._getGiftBtn.x = 119;
            this._getGiftBtn.y = 354;
            this._diamondTxt.visible = false;
            this._rewardNumBmpTxt.x = 262;
            return;
        }// end function

        private function setDayType2() : void
        {
            this._imgTip1.visible = false;
            this._imgTip2.visible = true;
            this._dayTxt.x = 52;
            this._rechargeNumTxt.visible = true;
            this._rechargeBtn.visible = true;
            this._getGiftBtn.x = 170;
            this._getGiftBtn.y = 340;
            this._diamondTxt.visible = true;
            this._rewardNumBmpTxt.x = 312;
            return;
        }// end function

        private function setStyle1() : void
        {
            return;
        }// end function

        private function setStyle2() : void
        {
            this._diamondTxt.visible = false;
            this._rechargeBtn.visible = false;
            this._getGiftBtn.x = 119;
            this._getGiftBtn.y = 354;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg.dispose(param1);
            this._imgTip1.dispose(param1);
            this._imgTip2.dispose(param1);
            this._rechargeBtn.dispose(param1);
            this._getGiftBtn.dispose(param1);
            this._dayTxt.dispose(param1);
            this._diamondBmp.dispose(param1);
            this._diamondTxt.dispose(param1);
            this._rechargeNumTxt.dispose(param1);
            this._item.dispose(param1);
            this._itemNumTxt.dispose(param1);
            this._rewardNumBmpTxt.dispose(param1);
            this._bg = null;
            this._imgTip1 = null;
            this._imgTip2 = null;
            this._rechargeBtn = null;
            this._getGiftBtn = null;
            this._dayTxt = null;
            this._diamondBmp = null;
            this._diamondTxt = null;
            this._rechargeNumTxt = null;
            this._item = null;
            this._itemNumTxt = null;
            this._rewardNumBmpTxt = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public static function get instance() : MoneyCardPackageWin
        {
            if (!_instance)
            {
                _instance = new MoneyCardPackageWin;
                _instance.layer = LayerManager.fullScreenTopLayer;
            }
            return _instance;
        }// end function

    }
}
